package com.example.community;

import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

//kafka测试
@SpringBootTest
public class testKafka {
    @Autowired
    private Kafka kafka;
    @Test
    void test() throws InterruptedException {
        kafka.sendMessage("test","你好");
        kafka.sendMessage("test","hhhh");
        Thread.sleep(10000);
    }
}
@Component
class Kafka{

    @Autowired
    private KafkaTemplate kafkaTemplate;
    public void sendMessage(String topic,String content){
        kafkaTemplate.send(topic,content);
    }
}
@Component
class KafkaComsumer{
    @KafkaListener(topics={"test"})
    public void handleMessage(ConsumerRecord record){
        System.out.println(record.value());
    }

}